# Generated from .\miniSysY.g4 by ANTLR 4.9.3
# encoding: utf-8
from antlr4 import *
from io import StringIO
import sys
if sys.version_info[1] > 5:
	from typing import TextIO
else:
	from typing.io import TextIO


def serializedATN():
    with StringIO() as buf:
        buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\26")
        buf.write("#\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2")
        buf.write("\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3")
        buf.write("\6\3\6\3\7\3\7\3\7\3\7\3\7\2\2\b\2\4\6\b\n\f\2\2\2\34")
        buf.write("\2\16\3\2\2\2\4\20\3\2\2\2\6\26\3\2\2\2\b\30\3\2\2\2\n")
        buf.write("\32\3\2\2\2\f\36\3\2\2\2\16\17\5\4\3\2\17\3\3\2\2\2\20")
        buf.write("\21\5\6\4\2\21\22\5\b\5\2\22\23\7\3\2\2\23\24\7\4\2\2")
        buf.write("\24\25\5\n\6\2\25\5\3\2\2\2\26\27\7\5\2\2\27\7\3\2\2\2")
        buf.write("\30\31\7\6\2\2\31\t\3\2\2\2\32\33\7\7\2\2\33\34\5\f\7")
        buf.write("\2\34\35\7\b\2\2\35\13\3\2\2\2\36\37\7\t\2\2\37 \7\13")
        buf.write("\2\2 !\7\n\2\2!\r\3\2\2\2\2")
        return buf.getvalue()


class miniSysYParser ( Parser ):

    grammarFileName = "miniSysY.g4"

    atn = ATNDeserializer().deserialize(serializedATN())

    decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]

    sharedContextCache = PredictionContextCache()

    literalNames = [ "<INVALID>", "'('", "')'", "'int'", "'main'", "'{'", 
                     "'}'", "'return'", "';'" ]

    symbolicNames = [ "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 
                      "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 
                      "<INVALID>", "Number", "Decimal_const", "Octal_const", 
                      "Hexadecimal_const", "Hexadecimal_prefix", "Nonzero_digit", 
                      "Octal_digit", "Digit", "Hexadecimal_digit", "WHITE_SPACE", 
                      "Annotation1", "Annotation2" ]

    RULE_compUnit = 0
    RULE_funcDef = 1
    RULE_funcType = 2
    RULE_ident = 3
    RULE_block = 4
    RULE_stmt = 5

    ruleNames =  [ "compUnit", "funcDef", "funcType", "ident", "block", 
                   "stmt" ]

    EOF = Token.EOF
    T__0=1
    T__1=2
    T__2=3
    T__3=4
    T__4=5
    T__5=6
    T__6=7
    T__7=8
    Number=9
    Decimal_const=10
    Octal_const=11
    Hexadecimal_const=12
    Hexadecimal_prefix=13
    Nonzero_digit=14
    Octal_digit=15
    Digit=16
    Hexadecimal_digit=17
    WHITE_SPACE=18
    Annotation1=19
    Annotation2=20

    def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
        super().__init__(input, output)
        self.checkVersion("4.9.3")
        self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
        self._predicates = None




    class CompUnitContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def funcDef(self):
            return self.getTypedRuleContext(miniSysYParser.FuncDefContext,0)


        def getRuleIndex(self):
            return miniSysYParser.RULE_compUnit

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterCompUnit" ):
                listener.enterCompUnit(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitCompUnit" ):
                listener.exitCompUnit(self)




    def compUnit(self):

        localctx = miniSysYParser.CompUnitContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_compUnit)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 12
            self.funcDef()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx


    class FuncDefContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def funcType(self):
            return self.getTypedRuleContext(miniSysYParser.FuncTypeContext,0)


        def ident(self):
            return self.getTypedRuleContext(miniSysYParser.IdentContext,0)


        def block(self):
            return self.getTypedRuleContext(miniSysYParser.BlockContext,0)


        def getRuleIndex(self):
            return miniSysYParser.RULE_funcDef

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterFuncDef" ):
                listener.enterFuncDef(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitFuncDef" ):
                listener.exitFuncDef(self)




    def funcDef(self):

        localctx = miniSysYParser.FuncDefContext(self, self._ctx, self.state)
        self.enterRule(localctx, 2, self.RULE_funcDef)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 14
            self.funcType()
            self.state = 15
            self.ident()
            self.state = 16
            self.match(miniSysYParser.T__0)
            self.state = 17
            self.match(miniSysYParser.T__1)
            self.state = 18
            self.block()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx


    class FuncTypeContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return miniSysYParser.RULE_funcType

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterFuncType" ):
                listener.enterFuncType(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitFuncType" ):
                listener.exitFuncType(self)




    def funcType(self):

        localctx = miniSysYParser.FuncTypeContext(self, self._ctx, self.state)
        self.enterRule(localctx, 4, self.RULE_funcType)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 20
            self.match(miniSysYParser.T__2)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx


    class IdentContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return miniSysYParser.RULE_ident

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterIdent" ):
                listener.enterIdent(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitIdent" ):
                listener.exitIdent(self)




    def ident(self):

        localctx = miniSysYParser.IdentContext(self, self._ctx, self.state)
        self.enterRule(localctx, 6, self.RULE_ident)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 22
            self.match(miniSysYParser.T__3)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx


    class BlockContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def stmt(self):
            return self.getTypedRuleContext(miniSysYParser.StmtContext,0)


        def getRuleIndex(self):
            return miniSysYParser.RULE_block

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterBlock" ):
                listener.enterBlock(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitBlock" ):
                listener.exitBlock(self)




    def block(self):

        localctx = miniSysYParser.BlockContext(self, self._ctx, self.state)
        self.enterRule(localctx, 8, self.RULE_block)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 24
            self.match(miniSysYParser.T__4)
            self.state = 25
            self.stmt()
            self.state = 26
            self.match(miniSysYParser.T__5)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx


    class StmtContext(ParserRuleContext):
        __slots__ = 'parser'

        def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
            super().__init__(parent, invokingState)
            self.parser = parser

        def Number(self):
            return self.getToken(miniSysYParser.Number, 0)

        def getRuleIndex(self):
            return miniSysYParser.RULE_stmt

        def enterRule(self, listener:ParseTreeListener):
            if hasattr( listener, "enterStmt" ):
                listener.enterStmt(self)

        def exitRule(self, listener:ParseTreeListener):
            if hasattr( listener, "exitStmt" ):
                listener.exitStmt(self)




    def stmt(self):

        localctx = miniSysYParser.StmtContext(self, self._ctx, self.state)
        self.enterRule(localctx, 10, self.RULE_stmt)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 28
            self.match(miniSysYParser.T__6)
            self.state = 29
            self.match(miniSysYParser.Number)
            self.state = 30
            self.match(miniSysYParser.T__7)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx





